//
//  NSMutableArray+Python.h
//  CommonTools
//
//  Created by caoyuan on 5/24/16.
//  Copyright © 2016 baidu. All rights reserved.
//

#import <Foundation/Foundation.h>

@interface NSMutableArray (Python)

typedef enum{
    ASCEND_ORDER    = 0,
    DESCEND_ORDER   = 1 << 0
}ENUM_CY_ARRAY_ORDER;


/**
 *  向数组内追加一个元素
 *  @用法 array.append(@"someValue").append(@"someValue")
 *  @return 返回数组本身
 */
- (NSMutableArray* (^)(id object))pyAppend;


/**
 *  弹出数组最后进入的元素，类似于栈的pop操作
 *  @用法 ary = ary.pop().pop().pop()
 *  @return ary本身
 */
- (NSMutableArray* (^)(void))pyPop;


/**
 *  remove 指定index的元素
 *  ary = ary.popIndex(@1)
 *  @return ary
 */
- (NSMutableArray* (^)(NSInteger index))pyPopIndex;


/**
 *  remove 数组中第一个你想删除的元素
 *  @用法 ary = ary.remove(@12).remove(@"3")
 *  @return ary 本身
 */
- (NSMutableArray* (^)(id object))pyRemove;


/**
 * 找到第一个你传进来value所在的index，没有反返回-1
 * @用法 index = ary.index(@"12")
 *  @return 反回一个NSInteger
 */
- (NSInteger (^)(id object))pyIndex;


/**
 *  安全的插入元素，可以插入nil，可以插入index=-1自动在0处插，最大处也一样
 *  @用法: ary = ary.insert(0, @"value");
 *  @return ary
 */
- (NSMutableArray* (^)(NSInteger index, id object))pyInsert;


/**
 *  获取子数组，ary2 = ary.range(start,end),start 如果比end小，就会反向
 *
 *  @return 返回数组
 */
- (NSMutableArray* (^)(NSInteger start, NSInteger end))pyRange;


/**
 *  替换index的元素
 * @用法 ary = ary.replace(2,@"value");
 *  @return 返回替换好的ary
 */
- (NSMutableArray* (^)(NSInteger index, id object))pyReplace;


- (id (^)(NSInteger))pyGetIndex;

/**
 *  翻转数组，ary = ary.reverse()
 *
 *  @return ary
 */
- (NSMutableArray* (^)(void))pyReverse;


/**
 *  对数组排序，升序和降序
 * @降序 ary = ary4.sorted(DESCEND_ORDER)
 * @升序 ary = ary4.sorted(ASCEND_ORDER)
 * @返回 排好序的MutableArray
 */
- (NSMutableArray *(^)(ENUM_CY_ARRAY_ORDER))pySorted;


/**
 *  for (eachElem,index) in List
 *
 *  @param block usage: [ary forEachIndexed:^(id each, NSUInteger index) { NSLog(@"-%@--%lu-",each,(unsigned long)index); }];
 */
- (void)forEachInArray: (void (^)(id eachElem, NSUInteger index))block;
/**
 *  for (eachElem, index) in xrange(start, end)
 *
 *  @param start NSUInteger start
 *  @param end   NSUInteger end
 *  @ usage [ary forEachInArrayRange:0 rangeEnd:5 enumerateBlock:^(id eachElem, NSInteger index) { NSLog(@"-%@--%lu-",each,(unsigned long)index); }];
 */
- (void)forEachInArrayRange:(NSInteger)start
                    rangEnd:(NSInteger)end
             enumerateblock:(void (^)(id eachElem, NSInteger index))block;


@end
